package com.jprocms.module.cms.api.dto;

import com.mzt.logapi.starter.annotation.DiffLogAllFields;
import com.mzt.logapi.starter.annotation.DiffLogField;
import lombok.Data;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.io.Serializable;
import java.util.Objects;

@Data
@DiffLogAllFields
public class OtherConfig implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 敏感词处理方式(0:不提示直接替换; 1:提示之后替换; 2:不允许提交;3 关闭敏感词)
     * 0-3。常用值1 2
     */
    @Min(0)
    @Max(2)
    @DiffLogField(name = "敏感词处理方式")
    private int sensitiveWordProcessModel = 1;

    /**
     * 敏感词替换词
     */
    @DiffLogField(name = "敏感词替换词")
    private String sensitiveReplaceWord;

    /**
     * 是否开启会员功能
     */
    @DiffLogField(name = "是否开启会员功能")
    private Boolean memberEnabled = true;

    /**
     * ip url限制每秒访问次数 0不限制
     */
    @DiffLogField(name = " ip url限制每秒访问次数")
    private int ipUrlLimitTimes = 0;
    /**
     * ip url限制 累计超过该限制 200次则认为是暴力访问，则加入黑名单
     */
    @DiffLogField(name = "ip url限制 累计超过该限制")
    private int ipUrlMaxExceedLimitTimes = 200;
    /**
     * ip 每小时访问接口错误次数 0不限制
     */
    @DiffLogField(name = "ip 每小时访问接口错误次数")
    private int ipErrorByHourLimit = 0;
    /**
     * ip 每小时攻击次数 0不限制
     */
    @DiffLogField(name = "ip 每小时攻击次数")
    private int ipAttachByHourLimit = 20;

    /**
     * ip 限制类型 1永久限制 2 限制1小时
     */
    @DiffLogField(name = "ip 限制类型 ")
    private int ipLimitType = 1;

    /**
     * ip 防火墙拦截是否开启 1开启 0 关闭
     */
    @DiffLogField(name = "防火墙拦截是否开启")
    private int ipLimitOpen = 1;

    /**
     *直接portal访问的开发场景下使用
     */
    private String contextPath;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        OtherConfig that = (OtherConfig) o;
        return sensitiveWordProcessModel == that.sensitiveWordProcessModel && ipUrlLimitTimes == that.ipUrlLimitTimes && ipLimitOpen == that.ipLimitOpen && ipLimitType == that.ipLimitType && ipErrorByHourLimit == that.ipErrorByHourLimit && ipAttachByHourLimit == that.ipAttachByHourLimit && Objects.equals(sensitiveReplaceWord, that.sensitiveReplaceWord);
    }

    @Override
    public int hashCode() {
        return Objects.hash(sensitiveWordProcessModel, sensitiveReplaceWord, ipUrlLimitTimes, ipLimitOpen, ipLimitType, ipErrorByHourLimit, ipAttachByHourLimit);
    }
}
